package scheduled;

import org.testng.annotations.Test;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Scheduled1 {

    public static void main(String[] args) {
        ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor)Executors.newScheduledThreadPool(10);
        for (int i = 0; i < 100; ++i) {
            executor.schedule(() -> System.out.println(Thread.currentThread().getName() + " run "), 2 , TimeUnit.SECONDS);

        }
        executor.shutdown();






        // 手动创建线程池
//        new ThreadPoolExecutor(1, 1, 1, TimeUnit.SECONDS, );


    }

    @Test
    private void t3() {

        // 虚拟机可得到的cpu核心数 12，但是本机其实是6核12线程
        int N_CPUS = Runtime.getRuntime().availableProcessors();
        System.out.println(N_CPUS);

        long maxMemory = Runtime.getRuntime().maxMemory();
        System.out.println(maxMemory);

        // 9223372036854775807
        System.out.println(Long.MAX_VALUE);
    }






}


